package com.kjlink.widget.monitoring.test.service;

import com.kjlink.widget.monitoring.annotation.MonitoringEventReport;
import com.kjlink.widget.monitoring.enums.EventTypeEnum;
import com.kjlink.widget.monitoring.enums.MonitorTypeEnum;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * 描述:
 *
 * @author Vic.xu
 * @since 2025-08-21 14:56
 */
@Service
public class AspectReportService {


    @MonitoringEventReport(eventType = EventTypeEnum.CREDENTIAL_TRANSFER_FAIL,
            monitorType = MonitorTypeEnum.HOST_APP,
            businessType = "test",
            businessIdParamExpress = "#id"
    )
    public void test(String id) {
        if (StringUtils.hasText(id)) {
            throw new IllegalStateException("id非空");
        }
    }

    @MonitoringEventReport(eventType = EventTypeEnum.CREDENTIAL_TRANSFER_FAIL,
            monitorType = MonitorTypeEnum.HOST_APP,
            businessType = "test",
            businessIdParamExpress = "#map['id']"
    )
    public void testTwo(Map<String, String> map) {
        if (map != null) {
            throw new IllegalStateException("map非空");
        }
    }

    @MonitoringEventReport(eventType = EventTypeEnum.CREDENTIAL_TRANSFER_FAIL,
            monitorType = MonitorTypeEnum.HOST_APP,
            businessType = "test",
            businessIdParamExpress = "#user.id"
    )
    public void testThree(ExpressModel user) {
        if (user != null) {
            throw new IllegalStateException("user not null");
        }
    }

    @Getter
    @Setter
    public static class ExpressModel {
        String id;
        String name;

       public ExpressModel(String id, String name) {
           this.id = id;
           this.name = name;
       }
    }
}
